<?php
require_once dirname(__FILE__).'/calendarSyncCommon.php';

set_time_limit(60000);
if(!isset($_SESSION['user_id'])){
    header("location: main.php");
}
$client = new apiClient();
if (isset($_SESSION['token'])) {
  $client->setAccessToken($_SESSION['token']);
}
$syncQ = new gCalendarSyncQ($_SESSION['user_id']);
if($syncQ->user_id==null) {
    $syncQ->user_id = $_SESSION['user_id'];
    $syncQ->calendar_id = $_SESSION['calender_id'];
    $syncQ->in_progress = false;
    $syncQ->last_sync = null;
    $syncQ->status = 'trial';
    $syncQ->sync_start = null;
    $syncQ->bootstrap_completed = false;
    
    $syncQ->insert();
}
$sync = new CalendarSyncController($syncQ);
//CalendarSyncUtil::debug('CalendarSyncController object', $sync);
$sync->SyncEvents(0,$client);
echo "<a href='main.php'>Back to Main</a>";
?>
